﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Spinning.Spinning.Unitity;
using Box2D.XNA;
using Microsoft.Xna.Framework;

namespace Spinning.Spinning.Entity
{
    class EnemyBoss : SingleGamePlayer
    {
        public EnemyBoss()
            : base()
        {
            Actor_Type = ActorType.Boss;
            ZIndex = Constants.enemy;
            Enemy_Type = EnemyType.Default;
        }

        public enum EnemyType
        {
            Wind, Water, Default
        }

        public EnemyType Enemy_Type
        {
            get;
            set;
        }

        public override void OnCreatBody(World world, PhysicConnectManager connectManager)
        {
            base.OnCreatBody(world, connectManager);
            Filter filter=new Filter();
            filter.categoryBits = (ushort)Constants.CategoryBitsBoss;
            filter.maskBits = (ushort)Constants.MaskBitsBoss;
            Filter = filter;
            _fixture.SetRestitution(1);
            _fixture.SetDensity(Constants.playerDensity);
        }

        public override void OnUpdate(GameTime gameTime)
        {
            base.OnUpdate(gameTime);
        }

        public override void BeginContact(Actor other)
        {
            base.BeginContact(other);
            if (other.Actor_Type == ActorType.Player)
            {
                SingleGamePlayer player = (SingleGamePlayer)other;
                switch (Enemy_Type)
                {
                    case EnemyType.Default:
                        player.MinusLifeTime(1);
                        break;
                    case EnemyType.Water:
                        player.MinusLifeTime(2);
                        break;
                    case EnemyType.Wind:
                        player.MinusLifeTime(3);
                        break;
                }
                isFlash = true;
            }
        }

        public override void HowToMove()
        {
            //base.doMove();
            int terminalVelocity = 25;
            Vector2 playVelocity = new Vector2();
            playVelocity.X = body.GetLinearVelocity().X + Accelerometer.X * 1.8f;
            playVelocity.Y = body.GetLinearVelocity().Y - Accelerometer.Y * 1.8f;

            if (playVelocity.X > terminalVelocity) playVelocity.X = terminalVelocity;
            if (playVelocity.X < -terminalVelocity) playVelocity.X = -terminalVelocity;

            if (playVelocity.Y > terminalVelocity) playVelocity.Y = terminalVelocity;
            if (playVelocity.Y < -terminalVelocity) playVelocity.Y = -terminalVelocity;
            body.SetLinearVelocity(playVelocity);
        }
    }
}
